<?php
namespace System\Controller;
use Common\AdminController;
use Common\Lib\Response;
class IndexController extends AdminController
{
    public function indexAction()
    {
        $this->assign('SITE_ASSET_URL',dirname($_SERVER['PHP_SELF']).C('SITE_ASSET_URL'));
        $this->display();
    }
    public function G_loginAction(){
        if(isset($_POST['username'])){
            $username=I('post.username','');
            $password=I('post.password','');
            if(empty($username) || empty($password) || strlen($username)<5 || strlen($password)<8 || strlen($username)>50 || strlen($password)>50){
                Response::failed();
                Response::go();
            }
            $res = D('UserLogin')->login($username,$password);
            if(200==$res){
                Response::success(L('LOGIN_SUCCESS'));
                Response::redirectUrl(U('System/Index/index'),'_self',2);
            }

            else
                Response::failed();
            Response::go();
        }else{
            $this->assign('SITE_ASSET_URL',dirname($_SERVER['PHP_SELF']).C('SITE_ASSET_URL'));
            $this->display();
        }

    }
    public function logoutAction(){
        D('UserLogin')->logout();
        Response::success(L('LOGOUT'));
        Response::redirectUrl(U('System/Index/G_login'),'_self',2);
        Response::go();
    }
}